//2009/07/27 10:29:46
#include <iostream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;

class FormatAmt
{
public:
    string amount(int dollars, int cents)
    {
        int d = dollars + int (cents/100);
        int c = cents % 100;
        string p;
        p.clear();
        p += "$";
        if (d/1000000000 > 0)
        {
            int x = d/1000000000;
            d %= 1000000000;
            p += convertIntegerToString(x) + ",";
        }
        if (d/1000000 > 0)
        {
            int x = d/1000000;
            d %= 1000000;
            string s = convertIntegerToString(x);
            if (p.size() > 1)
            {
                if (s.size() == 1)
                    p += "00" + s + ",";
                else if (s.size() == 2)
                    p += "0" + s + ",";
                else if (s.size() == 3)
                    p += s + ",";
            }
			else
				p += s + ",";
        }
        else if (p.size() > 1)
        {
            p += "000,";
        }
        if (d/1000 > 0)
        {
            int x = d /1000;
            d %= 1000;
            string s = convertIntegerToString(x);
			if(p.size() > 1)
			{
            if (s.size() == 1)
                p += "00" + s + ",";
            else if (s.size() == 2)
                p += "0" + s + ",";
            else if (s.size() == 3)
                p += s + ",";
			}
			else
				p += s + ",";
        }
        else if (p.size() > 1)
        {
            p += "000,";
        }
        if (d/1 > 0)
        {
            int x = d;
            string s = convertIntegerToString(x);
			if(p.size() > 1)
			{
            if (s.size() == 1)
                p += "00" + s + ".";
            else if (s.size() == 2)
                p += "0" + s + ".";
            else if (s.size() == 3)
                p += s + ".";
			}
			else
				p += s + ".";
        }
        else if (p.size() > 1)
        {
            p += "000.";
        }
        if (p.compare("$") == 0)
        {
            p += "0.";
        }
        if (c == 0)
        {
            p += "00";
        }
        else if (c>0 && c <10)
        {
            p += "0" + convertIntegerToString(c);
        }
        else
        {
            p += convertIntegerToString(c);
        }
        return p;
    }
private:
    string convertIntegerToString(int number)
    {
        stringstream s;
        s << number;
        return s.str();
    }
};
//1st: Take care with the string, integer things.
//2nd: Notice the situations of leading zeros.
